package com.ghck.shop.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ghck.shop.dao.FlowWaterMapper;
import com.ghck.shop.dao.MakerFlowWaterMapper;
import com.ghck.shop.dao.MakerRankMapper;
import com.ghck.shop.dao.ShopFlowWaterMapper;
import com.ghck.shop.model.BaseInfo;
import com.ghck.shop.model.MakerRank;
import com.ghck.shop.service.FlowService;
import com.ghck.shop.service.StatisticsService;

@Service
public class StatisticsServiceImpl implements StatisticsService{

	@Autowired
	private MakerRankMapper makerRankMapper;
	@Autowired
	private MakerFlowWaterMapper makerFlowWaterMapper;
	@Autowired
	private ShopFlowWaterMapper shopFlowWaterMapper;
	@Autowired
	private FlowWaterMapper flowWaterMapper;
	
	@Override
	public List<MakerRank> makerRankList(Integer type) {
		if(type == 0){
			return makerRankMapper.makerRankList("customerCount");
		}else if(type == 1){
			return makerRankMapper.makerRankList("tradingVolumes");
		}else if(type == 2){
			return makerRankMapper.makerRankList("percentage");
		}
		return makerRankMapper.makerRankList("customerCount");
	}

	@Override
	public BaseInfo getBaseInfo(Integer userId, Integer role) {
		BaseInfo baseInfo = new BaseInfo();
		//本月提成
		Integer monthPercentage = makerFlowWaterMapper.monthPercentage(userId);
		baseInfo.setMonthPercentage(monthPercentage == null ? 0: monthPercentage);
		//总提成
		Integer allPercentage = makerFlowWaterMapper.allPercentage(userId);
		baseInfo.setAllPercentage(allPercentage == null ? 0 : allPercentage);
		if(role == 3){
			//本月商铺收入
			Integer monthShopIncome = shopFlowWaterMapper.monthShopIncome(userId);
			baseInfo.setMonthShopIncome(monthShopIncome == null ? 0 : monthShopIncome);
			//商铺总收入
			Integer allShopIncome = shopFlowWaterMapper.allShopIncome(userId) ;
			baseInfo.setAllShopIncome(allShopIncome == null ? 0 : allShopIncome);
		}
		//我的余额
		Integer money = flowWaterMapper.myMoney(userId) ;
		baseInfo.setMoney(money == null ? 0 : money);
		return baseInfo;
	}

	@Override
	public void statisticsOrderMoney(Integer userId) {
		
	}
}